import * as types from '../mutation-types';

export default {
	state: {
		// 用户信息
		userInfo: {},
		// 用户验证
		token: '',
		// 是否登录
		isSignIn: false,
		// 登录次数
		signInTimes: 0,
	},
	getters: {
		user_signInTimes_getter(state) {
			return state.signInTimes;
		}
	},
	mutations: { // store.commit('');
		// 保存用户token
		[types.SET_USER_TOKEN](state, payload) {
			state.token = payload.token;
		},
		// 保存用户信息
		[types.SAVE_USER_INFO](state, payload) {
			state.userInfo = payload.userInfo;
		},
		// 保存用户登录状态
		[types.SAVE_USER_SIGNIN](state, payload) {
			state.isSignIn = payload.isSignIn;
		},
		// 统计用户登录次数
		[types.ADD_SIGNIN_TIME](state) {
			state.signInTimes++;
			console.log('登录次数(mutation)：' + state.signInTimes);
		}
	},
	actions: { // store.dispatch('');
		// 统计用户登录次数
		[types.ADD_SIGNIN_TIME_ASYNC](context) {
			console.log('经过action处理');
			context.commit('ADD_SIGNIN_TIME');
		},
	}
}